<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">

				<el-form-item>
					<el-input v-model="filters.accountName" placeholder="充值账号"></el-input>
				</el-form-item>
				<el-form-item>
					<el-input v-model="filters.phoneNum" placeholder="充值号码"></el-input>
				</el-form-item>
				<!--<el-form-item>-->
					<!--<el-input v-model="filters.rechargeState" placeholder="充值状态"></el-input>-->
				<!--</el-form-item>-->
				<el-form-item label="充值状态" prop="usertype">
					<el-select v-model="filters.rechargeState" placeholder="充值状态">
						<el-option value="0" label="全部">全部</el-option>
						<!--状态数值 1 充值中 2 充值成功 3充值失败  5订单达到 8失败后取消的订单 0 删除 -->
						<el-option value="1" label="充值中">充值中</el-option>
						<el-option value="2" label="充值成功">充值成功</el-option>
						<el-option value="3" label="充值失败">充值失败</el-option>
						<el-option value="5" label="订单达到">订单达到</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-input v-model="filters.amount" placeholder="充值金额"></el-input>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="开始时间"  format="yyyy-MM-dd"   v-model="filters.startTime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-date-picker type="date" placeholder="结束时间"  format="yyyy-MM-dd"   v-model="filters.endTime" style="width: 100%;"></el-date-picker>
				</el-form-item>
				<el-form-item>
					<el-input v-model="filters.flow" placeholder="移动流水号"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="findPageRecord">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="successOrders">批量成功</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="failtOrder">批量失败</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="againCommits">批量重新提交</el-button>
				</el-form-item>
			</el-form>
		</el-col>
		<!--列表-->
		<template>
			<el-table :data="recodes" highlight-current-row v-loading="loading" border @selection-change="selsChange" max-height="620"  style="width: 100%;">
				<el-table-column type="selection" width="55">
				</el-table-column>
				<el-table-column type="index" width="80" label="编号">
				</el-table-column>
				<el-table-column prop="electronicAccount.accountName" label="充值账号" show-overflow-tooltip >
				</el-table-column>
				<el-table-column prop="phoneNum" label="充值号码" show-overflow-tooltip  >
				</el-table-column>
				<el-table-column prop="city" label="地市" show-overflow-tooltip  >
				</el-table-column>
				<el-table-column prop="amount" label="充值金额" show-overflow-tooltip  >
				</el-table-column>
				<el-table-column prop="rechargeState" label="充值状态" show-overflow-tooltip :formatter="formatUserStatus" >
					<template slot-scope="scope">
						<el-tag :type="scope.row.rechargeState == 2 ? 'success' : scope.row.rechargeState == 3 ?  'danger' : 'info'"   >{{ scope.row.rechargeState === 1 ? '充值中' : scope.row.rechargeState === 2 ? '充值成功' :  scope.row.rechargeState === 3 ? '充值失败' :  scope.row.rechargeState === 5 ? '订单达到' : "其他"}} </el-tag>
					</template>
				</el-table-column>
				<el-table-column prop="startTime" label="创建时间" show-overflow-tooltip  width="170"  >
				</el-table-column>
				<el-table-column prop="endTime" label="完成时间" show-overflow-tooltip  width="170"  >
				</el-table-column>
				<el-table-column prop="chargeDetail" label="移动明细编号" show-overflow-tooltip   >
				</el-table-column>
				<el-table-column prop="flow" label="备注" show-overflow-tooltip show-overflow-tooltip   >
				</el-table-column>
				<el-table-column label="操作"    width="280">
					<template scope="scope"   >
						<el-button size="small" v-show="isShowSupper"  @click="successOrder(scope.$index, scope.row)">
							充值成功
						</el-button>
						<el-button size="small" v-show="isShowSupper"  @click="handleEnable(scope.$index, scope.row)">
						充值失败
						</el-button>
						<el-button size="small" v-show="isShowSupper"  @click="handleAgain(scope.$index, scope.row)">
							重新提交
						</el-button>
					</template>
				</el-table-column>
			</el-table>
		</template>
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>

	</section>

</template>
<script>
	import { findPageRecord ,failtRecord,failtRecords,successOrderEle,successOrdersEle,againCommit,againCommits} from '../../api/api';
	//import NProgress from 'nprogress'
    import moment from 'moment';
	export default {
		data() {
			return {
				filters: {
                    phoneNum: '',
                    rechargeState:'',
                    amount:'',
                    flow:'',
                    startTime:new Date(),
                    endTime:'',
                    accountName:''
				},
                isShowSupper:JSON.parse(sessionStorage.getItem("user")).usertype === 2 ? true : false,
				start:0,
				pageSize:10,
                total:0,
				loading: false,
				recodes: [],
                sels: [],//列表选中列
			}
		},
		methods: {
			//用户类型转换
            //<!--状态数值 1 充值中 2 充值成功 3充值失败  5订单达到 8失败后取消的订单 0 删除 -->
            formatUserStatus: function (row, column) {
                return row.rechargeState === 1 ? '充值中' : row.rechargeState === 2 ? '充值成功' :  row.rechargeState === 3 ? '充值失败' :  row.rechargeState === 5 ? '订单达到' : "其他";
            },
			//获取用户列表
            findPageRecord: function () {
				let para = {
                    rechargeState: this.filters.rechargeState == "0" ? "" : this.filters.rechargeState ,
					start:this.start,
					pageSize:this.pageSize,
                    flow:this.filters.flow,
                    accountName:this.filters.accountName,
                    amount:this.filters.amount,
                    phoneNum:this.filters.phoneNum,
                    startTime:this.filters.startTime == "" ? "" : moment(this.filters.startTime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD'),
                    endTime:this.filters.endTime == "" ? "" : moment(this.filters.endTime,"YYYY-MM-DD HH:mm:ss").format('YYYY-MM-DD'),
				};
				this.loading = true;
                findPageRecord(para).then(datas => {
                    this.loading = false;
                    //NProgress.done();
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.recodes = data.result;
                        this.total = data.totalCount;
                    }
                }).catch(e =>{

				});
			},handleCurrentChange:function(val){
                this.start = val - 1;
                this.findPageRecord();
			},
            handleSizeChange:function(val){
			    this.pageSize = val;
			    this.findPageRecord();
			},handleEnable: function (index, row) {
                this.$confirm('确认更新该订单状态吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    let para = {
                        rechargeState: "3",
                        recordId: row.recordId
                    };
                    failtRecord(para).then((res) => {
                        this.listLoading = false;
                        let { message, code, data } = res;
                        if (code !== "0") {
                            this.$message({
                                message: message,
                                type: 'error'
                            });
                        } else {
                            this.$message({
                                message: '操作成功',
                                type: 'success'
                            });
                        }
                        this.findPageRecord();
                    });
                });
            },failtOrder:function(){
                this.$confirm('确认批量更新订单状态吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    if(this.sels != null && this.sels.length > 0){
                        let para = {
                            records:this.sels
                        }
                        failtRecords(para).then((res) => {
                            this.listLoading = false;
                            let {message, code, data} = res;
                            if (code !== "0") {
                                this.$message({
                                    message: message,
                                    type: 'error'
                                });
                            } else {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                            }
                            this.findPageRecord();
                        });
                    }else{
                        this.$message({
                            message: '请选择订单',
                            type: 'error'
                        });
                    }
                });
			},selsChange: function (sels) {
                this.sels = sels;
            },successOrders:function () {
                this.$confirm('确认批量更新订单状态吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    if(this.sels != null && this.sels.length > 0){
                        let para = {
                            records:this.sels
                        }
                        successOrdersEle(para).then((res) => {
                            this.listLoading = false;
                            let {message, code, data} = res;
                            if (code !== "0") {
                                this.$message({
                                    message: message,
                                    type: 'error'
                                });
                            } else {
                                this.$message({
                                    message: '操作成功',
                                    type: 'success'
                                });
                            }
                            this.findPageRecord();
                        });
                    }else{
                        this.$message({
                            message: '请选择订单',
                            type: 'error'
                        });
                    }
                });
    		},successOrder:function (index, row) {
                this.$confirm('确认更新该订单状态吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    let para = {
                        recordId: row.recordId
                    };
                    successOrderEle(para).then((res) => {
                        this.listLoading = false;
                        let { message, code, data } = res;
                        if (code !== "0") {
                            this.$message({
                                message: message,
                                type: 'error'
                            });
                        } else {
                            this.$message({
                                message: '操作成功',
                                type: 'success'
                            });
                        }
                        this.findPageRecord();
                    });
                });
            },handleAgain:function (index, row) {
                this.$confirm('确认重新提交该订单吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    let para = {
                        recordId: row.recordId
                    };
                    againCommit(para).then((res) => {
                        this.listLoading = false;
                        let { message, code, data } = res;
                        if (code !== "0") {
                            this.$message({
                                message: message,
                                type: 'error'
                            });
                        } else {
                            this.$message({
                                message: '操作成功',
                                type: 'success'
                            });
                        }
                        this.findPageRecord();
                    });
                });
            },againCommits:function () {
				this.$confirm('确认批量重新提交订单吗?', '提示', {
					type: 'warning'
				}).then(() => {
					if(this.sels != null && this.sels.length > 0){
						let para = {
							records:this.sels
						}
						againCommits(para).then((res) => {
							this.listLoading = false;
							let {message, code, data} = res;
							if (code !== "0") {
								this.$message({
									message: message,
									type: 'error'
								});
							} else {
								this.$message({
									message: '操作成功',
									type: 'success'
								});
							}
							this.findPageRecord();
						});
					}else{
						this.$message({
							message: '请选择订单',
							type: 'error'
						});
					}
				});
			}
		},

		mounted() {
			this.findPageRecord();
		}
	};

</script>

<style scoped>

</style>
